﻿<%@ Page Title="" MasterPageFile="~/BackOffice.master" Language="C#" AutoEventWireup="true"
    CodeBehind="CadastroImovel.aspx.cs" Inherits="JA.Web.Apresentacao.CadastroImovel" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ID="cHead" ContentPlaceHolderID="head" runat="server">
    <script type="text/jscript">
        function onlyNum() {

            if (event.keyCode < 44 || event.keyCode > 57) {
                event.returnValue = false;
            }

        } //fim da funcao
        function validaTamanho(valor, tamanho) {

            var e = window.event;
            var target;
            if (e.target) target = e.target;
            else if (e.srcElement) target = e.srcElement;

            if (valor.length > 0 && valor.length < tamanho) {
                alert("Este campo exige " + tamanho + " digitos");
                target.focus();
            }
        }
        function validaDecimal(valor, inteiros, decimais) {
            var reDecimalPt = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;
            var reDecimalEn = /^[+-]?((\d+|\d{1,3}(\,\d{3})+)(\.\d*)?|\.\d+)$/;
            var reDecimal = reDecimalPt;

            var pLang = "Pt";
            charDec = (pLang != "En" ? "," : ".");
            eval("reDecimal = reDecimal" + pLang);

            var e = window.event;
            var target;
            if (e.target) target = e.target;
            else if (e.srcElement) target = e.srcElement;

            if (reDecimal.test(valor)) {
                pos = valor.indexOf(charDec);
                decs = pos == -1 ? 0 : valor.length - pos - 1;
                ints = pos == -1 ? valor.length : pos;
                if (ints > inteiros) {
                    alert("Por favor, informe apenas " + inteiros + " casa(s) antes da virgula.");
                    target.focus();
                }
                if (decs > 0 && decs > decimais) {
                    alert("Por favor, informe apenas " + decimais + " casa(s) decimais.");
                    target.focus();
                }
            } else if (valor != null && valor != "") {
                alert("por favor, informe um número válido.");
                target.focus();
            }

        }
    </script>
</asp:Content>
<asp:Content ID="cMain" ContentPlaceHolderID="cphMain" runat="server">
    <div class="art-Block">
        <div class="art-Block-body">
            <div class="art-BlockHeader">
                <div class="l">
                </div>
                <div class="r">
                </div>
                <div class="art-header-tag-icon">
                    <div class="t">
                        Cadastro de Im&oacute;veis</div>
                </div>
            </div>
            <div class="art-BlockContent">
                <div class="art-BlockContent-tl">
                </div>
                <div class="art-BlockContent-tr">
                </div>
                <div class="art-BlockContent-bl">
                </div>
                <div class="art-BlockContent-br">
                </div>
                <div class="art-BlockContent-tc">
                </div>
                <div class="art-BlockContent-bc">
                </div>
                <div class="art-BlockContent-cl">
                </div>
                <div class="art-BlockContent-cr">
                </div>
                <div class="art-BlockContent-cc">
                </div>
                <div class="art-BlockContent-body">
                    <asp:UpdatePanel ID="upnImovel" runat="server">
                        <ContentTemplate>
                            <asp:TabContainer ID="tabImovel" runat="server" ActiveTabIndex="0">
                                <asp:TabPanel ID="tabPesquisa" runat="server" HeaderText="Pesquisa">
                                    <ContentTemplate>
                                        <div style="width: 98%;">
                                            <table style="width: 100%;">
                                                <tr>
                                                    <td>
                                                        C&oacute;digo
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
                                                        <asp:MaskedEditExtender ID="mskTxtId" runat="server" Mask="9999999" TargetControlID="txtId"
                                                            PromptCharacter="" />
                                                    </td>
                                                    <td>
                                                        Titulo
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtTitulo" runat="server"></asp:TextBox>
                                                    </td>
                                                    <td>
                                                        Cliente
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddlCliente" runat="server" DataTextField="nome" DataValueField="idCliente">
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Bairro
                                                    </td>
                                                    <td>
                                                        <asp:DropDownList runat="server" ID="ddlBairro" DataTextField="bairro" DataValueField="idBairro"
                                                            Width="122" Style="margin-left: 2px;" />
                                                    </td>
                                                    <td>
                                                        CEP
                                                    </td>
                                                    <td>
                                                        <asp:TextBox runat="server" ID="txtCEP" MaxLength="45" />
                                                        <asp:MaskedEditExtender ID="txtCEP_MaskedEditExtender" TargetControlID="txtCEP" Mask="99999-999"
                                                            runat="server" />
                                                    </td>
                                                    <td>
                                                        Endereço
                                                    </td>
                                                    <td>
                                                        <asp:TextBox runat="server" ID="txtEndereco" MaxLength="75" Width="275" Style="margin-left: 1px;" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Ativos?
                                                    </td>
                                                    <td>
                                                        <asp:RadioButton ID="rbAtivoSim" runat="server" GroupName="Ativo" Text="Sim" />
                                                        <asp:RadioButton ID="rbAtivoNao" runat="server" GroupName="Ativo" Text="Não" />
                                                        <asp:RadioButton ID="rbAtivoNDA" runat="server" GroupName="Ativo" Text="NDA" Checked="true" />
                                                    </td>
                                                    <td>
                                                        Publicados?
                                                    </td>
                                                    <td>
                                                        <asp:RadioButton ID="rbPublicoSim" runat="server" GroupName="Publico" Text="Sim" />
                                                        <asp:RadioButton ID="rbPublicoNao" runat="server" GroupName="Publico" Text="Não" />
                                                        <asp:RadioButton ID="rbPublicoNda" runat="server" GroupName="Publico" Text="NDA"
                                                            Checked="true" />
                                                    </td>
                                                    <td>
                                                        &nbsp;
                                                    </td>
                                                    <td>
                                                        &nbsp;
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="6">
                                                        <asp:Button ID="btnPesquisa" runat="server" Text="Pesquisa" OnClick="btnPesquisa_Click" />
                                                        <br />
                                                        <br />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="6">
                                                        <asp:GridView ID="grvResultado" runat="server" AutoGenerateColumns="False" EmptyDataText="N&atilde;o foram encontrados registros nessa pesquisa!">
                                                            <Columns>
                                                                <asp:TemplateField>
                                                                    <ItemTemplate>
                                                                        <asp:ImageButton ID="imgbVisualizar" runat="server" OnClick="imgbVisualizar_Click"
                                                                            ImageUrl="~/App_Themes/Padrao/Imagens/backoffice/editar.gif" CommandArgument='<%#Eval("IdImovel") %>' />
                                                                    </ItemTemplate>
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                </asp:TemplateField>
                                                                <asp:BoundField DataField="IdImovel" HeaderText="ID" />
                                                                <asp:BoundField DataField="Titulo" HeaderText="Titulo" />
                                                                <asp:BoundField DataField="ClienteVO" HeaderText="Cliente" />
                                                                <asp:BoundField DataField="BairroVO" HeaderText="Bairro" />
                                                                <asp:BoundField DataField="CEP" HeaderText="CEP" />
                                                                <asp:BoundField DataField="endereco" HeaderText="Endereço" />
                                                                <asp:CheckBoxField DataField="Publicar" HeaderText="Publicado?" />
                                                                <asp:CheckBoxField DataField="Ativo" HeaderText="Ativo?" />
                                                            </Columns>
                                                        </asp:GridView>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </ContentTemplate>
                                </asp:TabPanel>
                                <asp:TabPanel ID="tabCadastro" runat="server" HeaderText="Cadastro">
                                    <ContentTemplate>
                                        <asp:Panel ID="panelCad" runat="server">
                                            <div style="width: 98%;">
                                                <table style="width: 100%;">
                                                    <tr>
                                                        <td>
                                                            C&oacute;digo:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadId" runat="server" Enabled="False"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            T&iacute;tulo:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadTitulo" runat="server" Width="450px" MaxLength="45"></asp:TextBox>
                                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtCadTitulo"
                                                                ErrorMessage="*" ValidationGroup="Salvar" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Descri&ccedil;&atilde;o
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadDescricao" runat="server" Width="450px" TextMode="MultiLine"
                                                                Height="200"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Endere&ccedil;o:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadEndereco" runat="server" MaxLength="75" Width="300"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Número:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadNumero" runat="server" MaxLength="45"></asp:TextBox>
                                                            <asp:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="9999999" TargetControlID="txtCadNumero"
                                                                PromptCharacter="" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Complemento:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadComplemento" runat="server" MaxLength="45"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Cep:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadCEP" runat="server" MaxLength="45"></asp:TextBox>
                                                            <asp:MaskedEditExtender ID="txtCadCEP_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
                                                                CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
                                                                CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
                                                                Enabled="True" Mask="99999-999" TargetControlID="txtCadCEP" ClearMaskOnLostFocus="true">
                                                            </asp:MaskedEditExtender>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Valor Total de Venda
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadVlrTotVen" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,2);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Permuta?
                                                        </td>
                                                        <td>
                                                            <asp:CheckBox ID="cbCadPermuta" runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Area &Uacute;til
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadAreaUtil" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Area Total
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadAreaTotal" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Valor Condom&iacute;nio
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadVlrCondominio" runat="server" MaxLength="12" Width="120px"
                                                                onkeypress="onlyNum();" onblur="validaDecimal(this.value,12,2);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Quartos
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadQuartos" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Su&iacute;tes
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadSuites" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Vagas Garagem
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadVagasGaragem" runat="server" MaxLength="12" Width="120px"
                                                                onkeypress="onlyNum();" onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Andares
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadAndares" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Unidade por Andar
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadUnidAndar" runat="server" MaxLength="12" Width="120px" onkeypress="onlyNum();"
                                                                onblur="validaDecimal(this.value,12,0);"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Ativo?
                                                        </td>
                                                        <td>
                                                            <asp:CheckBox ID="cbCadAtivo" runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Publicar?
                                                        </td>
                                                        <td>
                                                            <asp:CheckBox ID="cbCadPublicar" runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Obs
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtCadObs" runat="server" Width="450px" TextMode="MultiLine" Height="200"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Tipo
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadTipo" runat="server" DataValueField="idTipo" DataTextField="tipo"
                                                                OnSelectedIndexChanged="ddlCadTipo_SelectedIndexChanged" AutoPostBack="true">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Categoria
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadCategoria" runat="server" DataValueField="idCategoria"
                                                                DataTextField="categoria">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Estado
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadEstado" runat="server" DataValueField="siglaUf" DataTextField="uf"
                                                                OnSelectedIndexChanged="ddlCadEstado_SelectedIndexChanged" AutoPostBack="true">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Cidade
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadCidade" runat="server" DataValueField="idCidade" DataTextField="cidade"
                                                                OnSelectedIndexChanged="ddlCadCidade_SelectedIndexChanged" AutoPostBack="true">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Bairro
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadBairro" runat="server" DataValueField="idBairro" DataTextField="bairro">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            Cliente
                                                        </td>
                                                        <td>
                                                            <asp:DropDownList ID="ddlCadCliente" runat="server" DataValueField="idCliente" DataTextField="nome">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="vertical-align: top;">
                                                            Data Cadastro:
                                                        </td>
                                                        <td>
                                                            <asp:Literal ID="ltDataCadastro" runat="server"></asp:Literal>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="vertical-align: top;">
                                                            Cadastrado por:
                                                        </td>
                                                        <td>
                                                            <asp:Literal ID="ltCadastradoPor" runat="server"></asp:Literal>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="vertical-align: top;">
                                                            Data Edi&ccedil;&atilde;o:
                                                        </td>
                                                        <td>
                                                            <asp:Literal ID="ltDataEdicao" runat="server"></asp:Literal>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="vertical-align: top;">
                                                            Editado por:
                                                        </td>
                                                        <td>
                                                            <asp:Literal ID="ltEditadoPor" runat="server"></asp:Literal>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2">
                                                            <span style="color: Red;">(*) Campos Obrigatórios </span>
                                                            <br />
                                                            <br />
                                                            <br />
                                                            <asp:Button ID="btnSalvar" runat="server" Enabled="False" OnClick="btnSalvar_Click"
                                                                Text="Salvar" ValidationGroup="Salvar" UseSubmitBehavior="false" />
                                                            &nbsp;<asp:Button ID="btnCancelar" runat="server" OnClick="btnCancelar_Click" Text="Cancelar"
                                                                UseSubmitBehavior="false" />
                                                            <asp:Button ID="btnEditar" runat="server" Enabled="False" OnClick="btnEditar_Click"
                                                                Text="Editar" UseSubmitBehavior="false" />
                                                            &nbsp;<asp:Button ID="btnExcluir" runat="server" Enabled="False" OnClick="btnExcluir_Click"
                                                                Text="Excluir" UseSubmitBehavior="false" />
                                                            &nbsp;<asp:Button ID="btnNovo" runat="server" OnClick="btnNovo_Click" Text="Novo"
                                                                UseSubmitBehavior="false" />
                                                            <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="btnExcluir"
                                                                ConfirmText="Confirma a exclus&atilde;o do im&oacute;vel?">
                                                            </asp:ConfirmButtonExtender>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </asp:Panel>
                                    </ContentTemplate>
                                </asp:TabPanel>
                                <asp:TabPanel ID="tabCaracteristicas" runat="server" HeaderText="Caracteristicas">
                                    <ContentTemplate>
                                        <asp:Panel ID="panelCaracteristicas" runat="server">
                                            <asp:GridView ID="GridViewCaracteristicas" runat="server" AutoGenerateColumns="False"
                                                Enabled="False">
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="cbxCaracteristica" runat="server" />
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                        </EditItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="IdCaracteristica" HeaderText="Id" />
                                                    <asp:BoundField DataField="Caracteristica" HeaderText="Caracteristica" />
                                                </Columns>
                                            </asp:GridView>
                                        </asp:Panel>
                                    </ContentTemplate>
                                </asp:TabPanel>
                                <asp:TabPanel ID="tabAreasComuns" runat="server" HeaderText="Areas Comuns">
                                    <ContentTemplate>
                                        <asp:Panel ID="panelAreasComuns" runat="server">
                                            <asp:GridView ID="GridViewAreasComuns" runat="server" AutoGenerateColumns="False"
                                                Enabled="False">
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="cbxAreaComum" runat="server" />
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                        </EditItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="IdAreaComum" HeaderText="Id" />
                                                    <asp:BoundField DataField="AreaComum" HeaderText="Area Comum" />
                                                </Columns>
                                            </asp:GridView>
                                        </asp:Panel>
                                    </ContentTemplate>
                                </asp:TabPanel>
                            </asp:TabContainer>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
